package com.yvan.serverless.utils;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;

import java.io.IOException;
import java.sql.Timestamp;

public class TimestampToLongString extends ToStringSerializer {

    public final static ToStringSerializer instance = new TimestampToLongString();

    @Override
    public void serialize(Object value, JsonGenerator gen, SerializerProvider provider)
            throws IOException {
        if (value instanceof Timestamp) {
            gen.writeString(Long.toString(((Timestamp) value).getTime()));
        } else {
            gen.writeString(value.toString());
        }
    }
}
